 #@layout()
 #define content()

<span class="layui-breadcrumb">
  <a href="/">首页</a>
  <a href="/admin/myWebsitePublish"><cite>发布内容</cite></a>
</span>

<hr>
<br/>

<div class="layui-fluid">
	<div class="layui-row">
		<div class="layui-col-sm1">
			&nbsp;
		</div>
		<div class="layui-col-sm9">
			<div class="layui-form">
				<!-- 提示：如果你不想用form，你可以换成div等任何一个普通元素 -->
			
				<div class="layui-form-item">
					<div class="layui-inline" id="treeSelect" >
						<label class="layui-form-label">请选择栏目</label>
					</div>
				</div>
			
			</div>
			
			<hr>
			
			<form class="layui-form" id="detailForm">
			
				<input type="hidden" name="id" value="#(vo.id)">
			
				<div class="layui-form-item">
					<label class="layui-form-label">标题</label>
					<div class="layui-input-block">
						<input type="text" name="title" placeholder="请输入" value="#(vo.title)"
							autocomplete="off" class="layui-input" 
							lay-verify="required">
					</div>
				</div>
				
				<div class="layui-form-item">
					<div class="layui-inline">
						<label class="layui-form-label">发布日期</label>
					    <div class="layui-input-inline">
					    		<input type="text" name="publishTime" id="publishTime" lay-verify="date"
					    				value="#(attribute_map.publishTime)"
					    			 placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
					    </div>
					</div>
					<div class="layui-inline">
						<label class="layui-form-label">排序</label>
						<div class="layui-input-block">
							<input type="number" name="px" placeholder="请输入" value="#(vo.px)"
								autocomplete="off" class="layui-input" 
								lay-verify="required">
						</div>
					</div>
				</div>
				
				<div class="layui-form-item">
					<label class="layui-form-label">内容</label>
					<div class="layui-input-block">
						<textarea placeholder="请输入内容" class="layui-textarea" id="content" name="content">#(attribute_map.content)</textarea>
					</div>
				</div>
				
				<div class="layui-form-item">
					<div class="layui-input-block">
						<button type="button" class="layui-btn" lay-submit lay-filter="detailForm">保存</button>
						<button type="reset" class="layui-btn layui-btn-primary">重置</button>
					</div>
				</div>
				
			</form>
			
		</div>
	</div>
</div>


#end

#define js()

<script>

var websiteColumnId="#(websiteColumnId)";
var module="#(module)";

function initTree(){
	$("#treeElem").html("");
	$.ajax({
		type:'get',
		url:'/admin/myWebsiteColumn/tree',
		data:'websiteColumnId='+websiteColumnId+'&module='+module,
		success:function(data){
			if(data.code=='0'){
				nodes=data.data;
				
				layui.use('treeSelect',function(){
					var treeSelect=layui.treeSelect;
					treeSelect.init("#treeSelect",{
						nodes:nodes,
						data:websiteColumnId
					});
				});
				
			}
		}
	});
}

initTree();

myCkeditor('content' );


layui.use(['form','laydate'], function() {
	var form = layui.form;
	var $ = layui.$;
	var layer = layui.layer;
	var laydate = layui.laydate;
	laydate.render({
		elem: '#publishTime'
	});
	
	form.verify(layuiFormVerify);
	
	form.on('submit(detailForm)', function(data) {
		//建议使用ajax在此处提交。
		
		var obj={};
		var attribute={};
		obj.id=$(":input[name='id']").val();
		obj.px=$(":input[name='px']").val();
		obj.websiteColumnId=websiteColumnId;
		obj.title=$(":input[name='title']").val();
		
		attribute.content=CKEDITOR.instances.content.getData();
		attribute.publishTime=$(":input[name='publishTime']").val();
		obj.attribute=JSON.stringify(attribute);
		
		layer.load(1,{shade:0.5})
		$.ajax({
			type : 'post',
			url : '/admin/myWebsite/publish/save',
			data : obj,
			success : function(data) {
				if (data.code == "0") {
					layer.msg('保存成功！', {
						time : 600
					}, function() {
						window.location.href = "/admin/myWebsiteContent";
					});
				}
			}
		});
		//此处使用异步的好处，服务器端可以直接验证，如果直接提交，提交完成以后，如果验证不通过，那么不方便处理错误的信息
		return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
	});

});

</script>

#end


